# https://adworld.xctf.org.cn/contest/list?rwNmOdr=1699408336950

import requests
import execjs
import csv

cookies = {
    'cngizm2ziytq3mwy': 'optcpF1urQE8rw1vpltn9V1ku0V06BItuUh/sh914Ux1szMJog==',
    'fogq4n2exnzc0otg': 'AgcJOAADWABcUlZfBVlfAA9cSEJCSRBCHkJOQRhNRkkfQHNxAg==',
}

headers = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Language': 'zh-CN',
    'Connection': 'keep-alive',
    # 'Cookie': 'cngizm2ziytq3mwy=optcpF1urQE8rw1vpltn9V1ku0V06BItuUh/sh914Ux1szMJog==; fogq4n2exnzc0otg=AgcJOAADWABcUlZfBVlfAA9cSEJCSRBCHkJOQRhNRkkfQHNxAg==',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
    'en2uwnjgxodjhogi': '1',
    'rdmje1ymjkyzrknj': 'BwQEOx5LChoFGhwKHCYJAxRXTlY1EQkUFxteU18uM2J4ZxAuKC4nPDpvYG4sIzwkITMmEjs+MTY/f2V9HE5JTUoHCAZHXE9CRXFFSw8LEgkCB1EHUF8BAw4MBV4JNjpmYzUzYTc+PToyaWltPnNxMT03d3V4b3poRXd4PSfDgtmBhoGEgtLejdGLjt+NwsrEkcCRxcDLyZucn8fMmvfi7+OhobKypqSnuez2qay9o7X+97Khs7SsmLW0v7edztbN1oSeldhQ',
    'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'xhnjc3odeyndrhmj': 'BwcBOD0nISAdHB8+DgMGEwICMQ==',
}
file_js = open('混淆JS.js','r',encoding='utf-8').read()
qmze1yzvhyzcyyjr = execjs.compile(file_js).call('by_page_encrypt',2)

params = {
    'qmze1yzvhyzcyyjr': qmze1yzvhyzcyyjr,
}

response = requests.get(
    'https://adworld.xctf.org.cn/api/event/release_event/list/',
    params=params,
    cookies=cookies,
    headers=headers,
)
result_data = execjs.compile(file_js).call('decrypt_data',response.text)

# 行标题
row_title = ['id','release_name','release_sponsor','competition_type','competition_mode','competition_start_time','competition_end_time','sign_up_start_time','sign_up_end_time','release_cover','is_comment_open','is_official','hash','competition_url','create_time','inside','is_pass','is_topping','classes','event_hash','event_type','event_status','avg_rating','check_event','check_xctf','is_test_event','order_start_time','order_end_time']

# 写入 csv 文件
with open("data.csv",'w',newline='',encoding='utf-8') as csvfile:
    # 创建 csv 写入器
    writer = csv.writer(csvfile)
    # 写入标题行
    writer.writerow(row_title)
    # 写入行数据
    for index,item in enumerate(result_data['data']['rows']):
        writer.writerow([item.get(title,'') for title in row_title])
    print('文件写入成功')


